/*     */ package com.zimbra.cs.account;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class EntrySearchFilter
/*     */ {
/*     */   private static Set<String> sIndexedAttrs;
/*     */   private Term mTerm;
/*     */   
/*     */   public static enum AndOr
/*     */   {
/*  28 */     and, 
/*  29 */     or;
/*     */     
/*     */     private AndOr() {} }
/*     */   
/*  33 */   public static enum Operator { eq, 
/*  34 */     has, 
/*  35 */     startswith, 
/*  36 */     endswith, 
/*  37 */     ge, 
/*  38 */     le, 
/*  39 */     gt, 
/*  40 */     lt;
/*     */     
/*     */     private Operator() {}
/*     */   }
/*     */   
/*     */   public static abstract interface Visitor { public abstract void visitSingle(EntrySearchFilter.Single paramSingle);
/*     */     
/*     */     public abstract void enterMulti(EntrySearchFilter.Multi paramMulti);
/*     */     
/*     */     public abstract void leaveMulti(EntrySearchFilter.Multi paramMulti); }
/*     */   
/*  51 */   public static abstract class Term { public boolean isNegation() { return this.mNegation; }
/*  52 */     public void setNegation(boolean negation) { this.mNegation = negation; }
/*     */     
/*     */     private boolean mNegation;
/*     */     protected abstract void visit(EntrySearchFilter.Visitor paramVisitor);
/*     */   }
/*     */   
/*     */   public static class Multi extends EntrySearchFilter.Term { private EntrySearchFilter.AndOr mAndOr;
/*     */     private List<EntrySearchFilter.Term> mTerms;
/*     */     
/*  61 */     public Multi(boolean negation, EntrySearchFilter.AndOr andOr) { setNegation(negation);
/*  62 */       this.mAndOr = andOr;
/*  63 */       this.mTerms = new ArrayList();
/*     */     }
/*     */     
/*     */     public Multi(boolean negation, EntrySearchFilter.AndOr andOr, EntrySearchFilter.Term... terms) {
/*  67 */       this(negation, andOr);
/*  68 */       for (EntrySearchFilter.Term t : terms) {
/*  69 */         add(t);
/*     */       }
/*     */     }
/*     */     
/*  73 */     public List<EntrySearchFilter.Term> getTerms() { return this.mTerms; }
/*  74 */     public boolean isAnd() { return EntrySearchFilter.AndOr.and.equals(this.mAndOr); }
/*  75 */     public void add(EntrySearchFilter.Term t) { this.mTerms.add(t); }
/*     */     
/*     */     protected void visit(EntrySearchFilter.Visitor visitor) {
/*  78 */       visitor.enterMulti(this);
/*  79 */       for (EntrySearchFilter.Term t : this.mTerms) {
/*  80 */         t.visit(visitor);
/*     */       }
/*  82 */       visitor.leaveMulti(this);
/*     */     }
/*     */   }
/*     */   
/*     */   public static class Single extends EntrySearchFilter.Term
/*     */   {
/*     */     private String mLhs;
/*     */     private EntrySearchFilter.Operator mOp;
/*     */     private String mRhs;
/*     */     
/*     */     public Single(boolean negation, String lhs, String op, String rhs) throws IllegalArgumentException
/*     */     {
/*  94 */       this(negation, lhs, EntrySearchFilter.Operator.valueOf(op), rhs);
/*     */     }
/*     */     
/*     */     public Single(boolean negation, String lhs, EntrySearchFilter.Operator op, String rhs) {
/*  98 */       setNegation(negation);
/*  99 */       this.mLhs = lhs;this.mOp = op;this.mRhs = rhs;
/*     */     }
/*     */     
/* 102 */     public String getLhs() { return this.mLhs; }
/* 103 */     public EntrySearchFilter.Operator getOperator() { return this.mOp; }
/* 104 */     public String getRhs() { return this.mRhs; }
/*     */     
/*     */ 
/* 107 */     protected void visit(EntrySearchFilter.Visitor visitor) { visitor.visitSingle(this); }
/*     */   }
/*     */   
/*     */   static {
/* 111 */     sIndexedAttrs = new HashSet();
/*     */     
/*     */ 
/* 114 */     sIndexedAttrs.add("objectClass".toLowerCase());
/* 115 */     sIndexedAttrs.add("zimbraForeignPrincipal".toLowerCase());
/* 116 */     sIndexedAttrs.add("zimbraId".toLowerCase());
/* 117 */     sIndexedAttrs.add("zimbraMailCatchAllAddress".toLowerCase());
/* 118 */     sIndexedAttrs.add("zimbraMailDeliveryAddress".toLowerCase());
/* 119 */     sIndexedAttrs.add("zimbraMailForwardingAddress".toLowerCase());
/* 120 */     sIndexedAttrs.add("zimbraMailAlias".toLowerCase());
/* 121 */     sIndexedAttrs.add("zimbraDomainName".toLowerCase());
/* 122 */     sIndexedAttrs.add("uid".toLowerCase());
/* 123 */     sIndexedAttrs.add("mail".toLowerCase());
/* 124 */     sIndexedAttrs.add("cn".toLowerCase());
/* 125 */     sIndexedAttrs.add("sn".toLowerCase());
/* 126 */     sIndexedAttrs.add("gn".toLowerCase());
/* 127 */     sIndexedAttrs.add("displayName".toLowerCase());
/* 128 */     sIndexedAttrs.add("zimbraCalResSite".toLowerCase());
/* 129 */     sIndexedAttrs.add("zimbraCalResBuilding".toLowerCase());
/* 130 */     sIndexedAttrs.add("zimbraCalResFloor".toLowerCase());
/* 131 */     sIndexedAttrs.add("zimbraCalResRoom".toLowerCase());
/* 132 */     sIndexedAttrs.add("zimbraCalResCapacity".toLowerCase());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public EntrySearchFilter(Term term)
/*     */   {
/* 143 */     this.mTerm = term;
/*     */   }
/*     */   
/*     */   public void andWith(EntrySearchFilter other) {
/* 147 */     Term otherTerm = other.mTerm;
/* 148 */     if ((this.mTerm instanceof Multi)) {
/* 149 */       Multi m = (Multi)this.mTerm;
/* 150 */       if (m.isAnd()) {
/* 151 */         m.add(otherTerm);
/* 152 */         return;
/*     */       }
/*     */     }
/* 155 */     Multi multi = new Multi(false, AndOr.and);
/* 156 */     multi.add(this.mTerm);
/* 157 */     multi.add(otherTerm);
/* 158 */     this.mTerm = multi;
/*     */   }
/*     */   
/*     */   public void orWith(EntrySearchFilter other) {
/* 162 */     Term otherTerm = other.mTerm;
/* 163 */     if ((this.mTerm instanceof Multi)) {
/* 164 */       Multi m = (Multi)this.mTerm;
/* 165 */       if (!m.isAnd()) {
/* 166 */         m.add(otherTerm);
/* 167 */         return;
/*     */       }
/*     */     }
/* 170 */     Multi multi = new Multi(false, AndOr.or);
/* 171 */     multi.add(this.mTerm);
/* 172 */     multi.add(otherTerm);
/* 173 */     this.mTerm = multi;
/*     */   }
/*     */   
/*     */   public void traverse(Visitor visitor) {
/* 177 */     this.mTerm.visit(visitor);
/*     */   }
/*     */   
/*     */ 
/* 181 */   public boolean usesIndex() { return possiblyUsesIndex(this.mTerm); }
/*     */   
/*     */   private static boolean possiblyUsesIndex(Term term) {
/*     */     boolean result;
/*     */     boolean result;
/* 186 */     if ((term instanceof Single)) {
/* 187 */       Single single = (Single)term;
/* 188 */       result = sIndexedAttrs.contains(single.getLhs().toLowerCase());
/*     */     } else {
/* 190 */       assert ((term instanceof Multi));
/* 191 */       Multi multi = (Multi)term;
/* 192 */       boolean anding = multi.isAnd();
/* 193 */       List<Term> terms = multi.getTerms();
/* 194 */       boolean result; if (anding)
/*     */       {
/*     */ 
/* 197 */         result = false;
/* 198 */         for (Term t : terms) {
/* 199 */           if (possiblyUsesIndex(t)) {
/* 200 */             result = true;
/* 201 */             break;
/*     */           }
/*     */         }
/*     */       }
/*     */       else
/*     */       {
/* 207 */         result = true;
/* 208 */         for (Term t : terms) {
/* 209 */           if (!possiblyUsesIndex(t)) {
/* 210 */             result = false;
/* 211 */             break;
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 216 */     return result;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/EntrySearchFilter.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */